#include "auth.h"
#include <butil/logging.h>
#include <cppbase/utility.h>
namespace frpc
{
    int Auth::GenerateCredential(std::string *auth_str) const
    {
        *auth_str = AppGlobal::instance()->get_config("username");
        auth_str->append(":");
        auth_str->append(AppGlobal::instance()->get_config("password"));
        return 0;
    }

    int Auth::VerifyCredential(const std::string &auth_str,
                               const butil::EndPoint &client_addr,
                               brpc::AuthContext *out_ctx) const
    {
        if (strcmp(auth_str.data(), "guest:guest") == 0)
        {
            std::string u;
            u.resize(8);
            *(uint8_t *)u.data() = 1;
            out_ctx->set_user(u);
            return 0;
        }
        else
            return -1;
    }

}